<div class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">书 id</label>
        <div class="layui-input-block">
            <input type="text" name="novelId" required  lay-verify="required" placeholder="请输入 ID" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
    <div class="layui-input-block">
        <button class="layui-btn" lay-submit lay-filter="createBanner">立即提交</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
    </div>
</div>
<button type="button" class="layui-btn" id="uploadBannerCover">
    <i class="layui-icon">&#xe67c;</i>上传图片
</button>
<div>
    <img src="" alt="" id="bannerImg">
</div>
<script>
    layui.use(['admin','server','form','upload'],function(){
        var $ = layui.$;
        var form = layui.form;
        var setter = layui.setter;
        var server = layui.server;
        var admin = layui.admin;
        var upload = layui.upload;
        form.render();
        var options = {
            url: 'windman/createBanner',
            data: {
                novelId: '',
                url: '',
            },
            callback: function(success_data) {
                layer.msg('create success');
            }
        };
        var uploadInst = upload.render({
            elem: '#uploadBannerCover', //绑定元素
            url: setter.base_server + 'file/uploadBannerPic', //上传接口
            done: function(res){
                //上传完毕回调
                console.log(res);
                if (res.errorCode != 0) {
                    layer.msg(res.errorMessage, {icon: 2,time:1500});
                    return false;
                }
                var banner_url = res.resultData.n.url;
                $('#bannerImg').attr('src', banner_url);
                options.data.url = banner_url;
            },
            error: function(){
                //请求异常回调
            },
            field: 'img',
        });

        form.on('submit(createBanner)',function(data){
            var formValue = data.field;
            options.data.novelId = formValue.novelId;
            server.req(options);
        });
    })
</script>